<%= form_for @changeset, @action, [multipart: true, class: "ui form"], fn f -> %>
  <div class="field required <%= AdminHelpers.error_class(f, :name) %>">
    <%= label f, :name, "Name" %>
    <%= text_input f, :name, placeholder: "Apple, Inc." %>
    <%= AdminHelpers.error_message(f, :name) %>
  </div>

  <div class="two fields">
    <div class="fourteen wide field">
      <label for="avatar">
        Avatar
        <%= AdminHelpers.help_icon "Ideal size is 600px by 600px." %>
        <%= AdminHelpers.file_toggle_buttons() %>
      </label>
      <%= file_input(f, :avatar) %>
      <%= AdminHelpers.error_message(f, :avatar) %>
    </div>

    <div class="two wide field">
      <img src="<%= avatar_url(f.data, :small) %>" height=66>
    </div>
  </div>

  <div class="two fields">
    <div class="fourteen wide field">
      <label for="dark_logo">
        Dark Logo
        <%= AdminHelpers.help_icon "SVG is ideal. If PNG, best size is 800px by 800px." %>
        <%= AdminHelpers.file_toggle_buttons() %>
      </label>
      <%= file_input(f, :dark_logo) %>
      <%= AdminHelpers.error_message(f, :dark_logo) %>
    </div>

    <div class="two wide field">
      <img src="<%= logo_url(f.data, :dark_logo, :small) %>" height=66>
    </div>
  </div>

  <div class="two fields">
    <div class="fourteen wide field">
      <label for="color_logo">
        Color Logo
        <%= AdminHelpers.help_icon "SVG is ideal. If PNG, best size is 800px by 800px." %>
        <%= AdminHelpers.file_toggle_buttons() %>
      </label>
      <%= file_input(f, :color_logo) %>
      <%= AdminHelpers.error_message(f, :color_logo) %>
    </div>

    <div class="two wide field">
      <img src="<%= logo_url(f.data, :color_logo, :small) %>" height=66>
    </div>
  </div>

  <div class="three fields">
    <div class="field <%= AdminHelpers.error_class(f, :website) %>">
      <%= label f, :website %>
      <%= text_input f, :website, placeholder: "https://apple.com" %>
      <%= AdminHelpers.error_message(f, :website) %>
    </div>

    <div class="field <%= AdminHelpers.error_class(f, :github_handle) %>">
      <%= label f, :github_handle, "On GitHub" %>
      <%= text_input f, :github_handle, placeholder: "apple", mask: "slug" %>
      <%= AdminHelpers.error_message(f, :github_handle) %>
    </div>

    <div class="field <%= AdminHelpers.error_class(f, :twitter_handle) %>">
      <%= label f, :twitter_handle, "On Twitter" %>
      <%= text_input f, :twitter_handle, placeholder: "apple", mask: "slug" %>
      <%= AdminHelpers.error_message(f, :twitter_handle) %>
    </div>
  </div>

  <div class="field <%= AdminHelpers.error_class(f, :description) %>">
    <%= label f, :description %>
    <%= text_input f, :description, placeholder: "Apple leads the world in innovation with iPhone, iPad, Mac, Apple Watch and Apple TV." %>
    <%= AdminHelpers.error_message(f, :description) %>
  </div>

  <div class="field">
    <%= label(f, :reps) do %>
      Reps <%= AdminHelpers.help_icon("People with access to the sponsor dashboard") %>
    <% end %>

    <div class="ui middle aligned selection list js-sponsor_reps">
      <%= inputs_for f, :sponsor_reps, fn i -> %>
        <% rep = AdminHelpers.load_from_form(i, Person, :person) %>
        <div class="item <%= if AdminHelpers.is_persisted(i.data), do: "persisted" %>">
          <%= hidden_input(i, :person_id) %>
          <img class="ui avatar image" src="<%= ChangelogWeb.PersonView.avatar_url(rep) %>">

          <div class="content">
            <div class="header"><%= rep.name %> (@<%= rep.handle %>)</div>
          </div>

          <div class="right floated content">
            <div class="ui tiny icon button js-remove">
              <i class="remove icon"></i>
              <%= hidden_input(i, :delete) %>
            </div>
          </div>
        </div>
      <% end %>
    </div>

    <div class="ui search">
      <div class="ui left icon input">
        <input class="prompt" type="text" placeholder="Add a Rep">
        <i class="user icon"></i>
      </div>
    </div>
  </div>

  <div class="ui hidden divider"></div>
  <div class="ui equal width stackable grid">
  <%= if !AdminHelpers.is_persisted(f.data) do %>
    <div class="column"><%= AdminHelpers.submit_button(:primary, "Create") %></div>
    <div class="column"><%= AdminHelpers.submit_button(:secondary, "Create and Close", AdminHelpers.next_param(@conn, Routes.admin_sponsor_path(@conn, :index))) %></div>
  <% else %>
    <div class="column"><%= AdminHelpers.submit_button(:primary, "Save", SharedHelpers.current_path(@conn)) %></div>
    <div class="column"><%= AdminHelpers.submit_button(:secondary, "Save and Close", AdminHelpers.next_param(@conn)) %></div>
  <% end %>
    <div class="column"></div>
  </div>
<% end %>
